<?php
declare (strict_types=1);

namespace app\api\controller;

use think\response\Json;
use app\api\model\Feedback as FeedbackModel;

/**
 * 投诉建议
 * Class Feedback
 * @package app\api\controller\Feedback
 */
class Feedback extends Controller
{
    public function index(): Json
    {
        $model = new FeedbackModel;
        $params = $this->request->param();
        $params['user_id'] = $this->user['user_id'] ?? 0;
        $list = $model->getList($params)->toArray();
        return $this->renderSuccess([
            'total' => $list['total'],
            'items' => $list['data']
        ]);
    }
    
    public function add()
    {
        $model = new FeedbackModel;
        $data = $this->postForm();
        $data['user_id'] = $this->user['user_id'];
        if ($model->add($data)) {
            return $this->renderSuccess('提交成功');
        }
        return $this->renderError($model->getError() ?: '提交失败');
    }
}
